FUNCTION YBC_SWS_PREPARE_DATA .
*"--------------------------------------------------------------------
*"*"局部接口：
*"  IMPORTING
*"     VALUE(IV_HEADER) TYPE  ANY
*"  EXPORTING
*"     VALUE(ES_MSG) TYPE  BAPIRET2
*"  TABLES
*"      IT_ITEM TYPE  STANDARD TABLE OPTIONAL
*"      ET_HEAD_DATA STRUCTURE  YBCS_SWS_DATA_H OPTIONAL
*"      ET_ITEM_DATA STRUCTURE  YBCS_SWS_DATA_I OPTIONAL
*"--------------------------------------------------------------------

  DATA:
    GS_DES   TYPE REF TO CL_ABAP_STRUCTDESCR,
    LV_INDEX TYPE I,
    GS_COMP  TYPE ABAP_COMPDESCR.

  FIELD-SYMBOLS:
            <FS_VALUE> TYPE ANY.

  REFRESH:
    ET_HEAD_DATA[],
    ET_ITEM_DATA.

  GS_DES ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( IV_HEADER ).

  LOOP AT GS_DES->COMPONENTS INTO GS_COMP.
    IF GS_COMP-NAME = 'MANDT'.
      CONTINUE.
    ENDIF.

    CLEAR ET_HEAD_DATA.
    ET_HEAD_DATA-FIELD = GS_COMP-NAME.
    ASSIGN COMPONENT GS_COMP-NAME OF STRUCTURE IV_HEADER TO <FS_VALUE>.
    IF <FS_VALUE> IS ASSIGNED.
      ET_HEAD_DATA-VALUE = <FS_VALUE>.
    ENDIF.

    APPEND ET_HEAD_DATA.
  ENDLOOP.

  IF IT_ITEM[] IS NOT INITIAL.
    GS_DES ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( IT_ITEM ).

    LOOP AT IT_ITEM.
      LV_INDEX  = SY-TABIX.

      LOOP AT GS_DES->COMPONENTS INTO GS_COMP.
        IF GS_COMP-NAME = 'MANDT'.
          CONTINUE.
        ENDIF.

        CLEAR ET_ITEM_DATA.
        ET_ITEM_DATA-ITEM = LV_INDEX.
        ET_ITEM_DATA-FIELD = GS_COMP-NAME.
        ASSIGN COMPONENT GS_COMP-NAME OF STRUCTURE IT_ITEM TO <FS_VALUE>.
        IF <FS_VALUE> IS ASSIGNED.
          ET_ITEM_DATA-VALUE = <FS_VALUE>.
        ENDIF.

        APPEND ET_ITEM_DATA.
      ENDLOOP.
    ENDLOOP.
  ENDIF.
ENDFUNCTION.
